/*
 * HeapWorker.c
 *
 *  Created on: 2011-7-23
 *      Author: Donghan
 */
/*
 * An async worker thread to handle certain heap operations that
 * need to be done in a separate thread to avoid synchronization
 * problems.  HeapWorkers and reference clearing/enqueuing are
 * handled by this thread.
 */
#include "../Dalvik.h"
#include "HeapInternal.h"

#include <sys/time.h>
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
#include <errno.h>  // for ETIMEDOUT, etc.

static void* heapWorkerThreadStart(void* arg);

/*
 * Initialize any HeapWorker state that Heap.c
 * cares about.  This lets the GC start before the
 * HeapWorker thread is initialized.
 */
void dvmInitializeHeapWorkerState()
{
    assert(!gDvm.heapWorkerInitialized);

    dvmInitMutex(&gDvm.heapWorkerLock);
    pthread_cond_init(&gDvm.heapWorkerCond, NULL);
    pthread_cond_init(&gDvm.heapWorkerIdleCond, NULL);
    pthread_cond_init(&gDvm.gcHeapCond, NULL);

    gDvm.heapWorkerInitialized = true;
}
